package com.xls.resource.dialog;

import android.app.Activity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lzz.bottomencapsulation.entity.VersionEntity;
import com.lzz.bottomencapsulation.popupwindow.CenterBaseDialog;
import com.lzz.bottomencapsulation.utils.AppUtils;
import com.xls.resource.R;


/***
 @package ${package}
 @filename ${版本升级}
 */
public class APKInsDialog extends CenterBaseDialog implements View.OnClickListener {
    VersionEntity versionEntity;//新版本信息
    TextView daiTvOk;

    TextView ins_tv_content;
    ImageView daiBtnCancel;

    /**
     * @param activity
     */
    public APKInsDialog(Activity activity) {
        super(activity, true);
        setCanceledOnTouchOutside(false);//设置点击Dialog以外的地方不能让Dialog消失
    }

    public void setVersionEntity(VersionEntity versionEntity) {
        this.versionEntity = versionEntity;
    }

    @Override
    protected int getView() {
        return R.layout.dialog_apk_ins;
    }

    @Override
    protected void initView() {
        daiTvOk=findViewById(R.id.ins_btn_ok);
        ins_tv_content=findViewById(R.id.ins_tv_content);
        daiTvOk.setOnClickListener(this);
        daiBtnCancel=findViewById(R.id.ins_close);
        daiBtnCancel.setOnClickListener(this);
        setCanceledOnTouchOutside(!versionEntity.isForceUpdate());//设置点击Dialog以外的地方不能让Dialog消失
        if (versionEntity.isForceUpdate()) {
            daiBtnCancel.setVisibility(View.GONE);
        } else {
            daiBtnCancel.setVisibility(View.VISIBLE);
        }
        ins_tv_content.setText(versionEntity.getContent());
    }

    @Override
    public void onClick(View view) {
        if (view.getId()==R.id.ins_btn_ok){
            AppUtils.anZhuangAPk(context,versionEntity.getFilePath());
            dismiss();
        }else if (view.getId()==R.id.ins_close){
            dismiss();
        }
    }
}
